import { getReportedStatus,getUserGroupStatus } from '@/api/reported-data'

export default {
    methods: {
        getReportedStatus_mixins(dataList) {
            if (!Array.isArray(dataList) && dataList.length === 0) {
                return
            }
            return new Promise(resolve => {
                let ids = dataList.map(item => item.id)
                getReportedStatus(ids).then(({ code, message, data = {} }) => {
                    if (code !== 1) {
                        this.$Message.warning(message);
                        return
                    }
                    let items = data.items || []
                    items.forEach(element => {
                        dataList.forEach(subElement => {
                            if (subElement.id === element.id) {
                                subElement.reportedStatus = element.status
                                subElement.reportedMsg = element.msg
                            }
                        })
                    });
                }).finally(() => {
                    resolve()
                })
            })
        },
        getUserGroupStatus_mixins(dataList) {
            if (!Array.isArray(dataList) && dataList.length === 0) {
                return
            }
            return new Promise(resolve => {
                let ids = dataList.map(item => item.id)
                getUserGroupStatus(ids).then(({ code, message, data = {} }) => {
                    if (code !== 1) {
                        this.$Message.warning(message);
                        return
                    }
                    let items = data || []
                    items.forEach(element => {
                        dataList.forEach(subElement => {
                            if (subElement.id === element.id) {
                                subElement.reportedStatus = element.status
                                subElement.reportedMsg = element.msg
                            }
                        })
                    });
                }).finally(() => {
                    resolve()
                })
            })
        }
    }
}